using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_News", "newsId", "Torch.WL.ConnectionString")]
	public class Tb_News : Info
	{
		#region SQL column name consts 
		public const string SQLCOL_NEWSID = "newsId";
		public const string SQLCOL_CLASSID = "classId";
		public const string SQLCOL_TITLE = "title";
		public const string SQLCOL_NEWSDATE = "newsDate";
		public const string SQLCOL_CONTENT = "content";
		public const string SQLCOL_CONTENTIMG = "contentImg";
		public const string SQLCOL_HITTIMES = "hitTimes";
		public const string SQLCOL_CREATETIME = "createTime";
		#endregion


		#region Contructors
		/// <summary>
		/// Construct empty entity
		/// </summary>
		public Tb_News () {}

		/// <summary>
		/// Construct entity by primary key, other fields will be assigned by 
		/// "Load" method.
		/// </summary>
		public Tb_News (int newsId)
		{
			this.newsId = newsId;
		}
		#endregion

		public override void Init (DataRow row)
		{
			newsId = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_NEWSID]);
			classId = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_CLASSID]);
			title = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_TITLE]);
			newsDate = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_NEWSDATE]);
			content = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_CONTENT]);
			contentImg = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_CONTENTIMG]);
			hitTimes = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_HITTIMES]);
			createTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_CREATETIME]);
		}

		#region Properties 
		#region Property <int> newsId
		[Property("newsId", 4, SqlDbType.Int, true, true)]
		public int newsId 
		{
			get { return _newsId; }
			set { _newsId = value; }
		}
		private int _newsId = int.MinValue;
		#endregion

		#region Property <int> classId
		[Property("classId", 4, SqlDbType.Int, false, false)]
		public int classId 
		{
			get { return _classId; }
			set { _classId = value; }
		}
		private int _classId = int.MinValue;
		#endregion

		#region Property <string> title
		[Property("title", 200, SqlDbType.VarChar, false, false)]
		public string title 
		{
			get { return _title; }
			set { _title = value; }
		}
		private string _title = null;
		#endregion

		#region Property <DateTime> newsDate
		[Property("newsDate", 16, SqlDbType.DateTime, false, false)]
		public DateTime newsDate 
		{
			get { return _newsDate; }
			set { _newsDate = value; }
		}
		private DateTime _newsDate = DateTime.MinValue;
		#endregion

		#region Property <string> content
		[Property("content", 2147483647, SqlDbType.Text, false, false)]
		public string content 
		{
			get { return _content; }
			set { _content = value; }
		}
		private string _content = null;
		#endregion

		#region Property <string> contentImg
		[Property("contentImg", 100, SqlDbType.VarChar, false, false)]
		public string contentImg 
		{
			get { return _contentImg; }
			set { _contentImg = value; }
		}
		private string _contentImg = null;
		#endregion

		#region Property <int> hitTimes
		[Property("hitTimes", 4, SqlDbType.Int, false, false)]
		public int hitTimes 
		{
			get { return _hitTimes; }
			set { _hitTimes = value; }
		}
		private int _hitTimes = int.MinValue;
		#endregion

		#region Property <DateTime> createTime
		[Property("createTime", 16, SqlDbType.DateTime, false, false)]
		public DateTime createTime 
		{
			get { return _createTime; }
			set { _createTime = value; }
		}
		private DateTime _createTime = DateTime.MinValue;
		#endregion
		#endregion


		public bool LoadByIdentity(int newsId)
		{
			return DataAccess.SelectByIdentity(this, Convert.ToInt64(newsId));
		}


		public bool DeleteByIdentity()
		{
			return DataAccess.DeleteByIdentity(this);
		}
	}
}
